package com.xr.web.controller.miniprogram;

import com.xr.common.annotation.Log;
import com.xr.common.core.controller.BaseController;
import com.xr.common.core.domain.AjaxResult;
import com.xr.common.core.page.TableDataInfo;
import com.xr.common.enums.BusinessType;
import com.xr.common.utils.poi.ExcelUtil;
import com.xr.miniprogram.domain.MiniProgramQuickEntry;
import com.xr.miniprogram.service.IMiniProgramQuickEntryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * description: 首页快捷入口接口
 *
 * @author: wls
 * @date: 2023/11/9 9:37
 * @version:1.0
 */
@Api("首页快捷按钮接口")
@RestController
@RequestMapping("/mini/entry")
public class MpQuickEntryController extends BaseController {
    @Autowired
    private IMiniProgramQuickEntryService miniProgramQuickEntryService;

    /**
     * 查询首页快捷按钮列表
     */
    @ApiOperation("获取快捷按钮列表")
    @PreAuthorize("@ss.hasPermi('mini:entry:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniProgramQuickEntry miniProgramQuickEntry)
    {
        startPage();
        List<MiniProgramQuickEntry> list = miniProgramQuickEntryService.selectMiniProgramQuickEntryList(miniProgramQuickEntry);
        return getDataTable(list);
    }

    /**
     * 导出首页快捷按钮列表
     */
    @ApiOperation("导出快捷按钮")
    @PreAuthorize("@ss.hasPermi('mini:entry:export')")
    @Log(title = "首页快捷按钮", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniProgramQuickEntry miniProgramQuickEntry)
    {
        List<MiniProgramQuickEntry> list = miniProgramQuickEntryService.selectMiniProgramQuickEntryList(miniProgramQuickEntry);
        ExcelUtil<MiniProgramQuickEntry> util = new ExcelUtil<MiniProgramQuickEntry>(MiniProgramQuickEntry.class);
        util.exportExcel(response, list, "首页快捷按钮数据");
    }

    /**
     * 获取首页快捷按钮详细信息
     */
    @ApiOperation("根据id获取快捷按钮信息")
    @PreAuthorize("@ss.hasPermi('mini:entry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(miniProgramQuickEntryService.selectMiniProgramQuickEntryById(id));
    }

    /**
     * 新增首页快捷按钮
     */
    @ApiOperation("新增首页快捷按钮")
    @PreAuthorize("@ss.hasPermi('mini:entry:add')")
    @Log(title = "首页快捷按钮", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniProgramQuickEntry miniProgramQuickEntry)
    {
        return toAjax(miniProgramQuickEntryService.insertMiniProgramQuickEntry(miniProgramQuickEntry));
    }

    /**
     * 修改首页快捷按钮
     */
    @ApiOperation("修改首页快捷按钮")
    @PreAuthorize("@ss.hasPermi('mini:entry:edit')")
    @Log(title = "首页快捷按钮", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniProgramQuickEntry miniProgramQuickEntry)
    {
        return toAjax(miniProgramQuickEntryService.updateMiniProgramQuickEntry(miniProgramQuickEntry));
    }

    /**
     * 删除首页快捷按钮
     */
    @ApiOperation("删除首页快捷按钮[组]")
    @PreAuthorize("@ss.hasPermi('mini:entry:remove')")
    @Log(title = "首页快捷按钮", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(miniProgramQuickEntryService.deleteMiniProgramQuickEntryByIds(ids));
    }

}
